﻿using System;
using System.ComponentModel;

namespace Daun.Cores.Entities
{
    public class DocumentPropertyDescriptor : PropertyDescriptor 
    {
        private string _docCategeory;

        public override Type PropertyType
        {
            get { return typeof(string); }
        }
        public override bool IsReadOnly
        {
            get { return false; }
        }
        public override Type ComponentType
        {
            get { return typeof(DocumentProperty); }
        }
        public override string Category
        {
            get
            {
                return _docCategeory;
            }
        }

        public DocumentPropertyDescriptor(string name,string category) : base(name, null) 
        {
            _docCategeory = category;
        }
        public override object GetValue(object component) 
        {
            return ((DocumentProperty)component)[Name];
        }
        public override void SetValue(object component, object value) 
        {
            ((DocumentProperty)component)[Name] = (string)value;
        }
        public override void ResetValue(object component) 
        {
            ((DocumentProperty)component)[Name] = null;
        }
        public override bool CanResetValue(object component) 
        {
            return true;
        }
        public override bool ShouldSerializeValue(object component)
        {
            return ((DocumentProperty)component)[Name] != null;
        }        
    }
}
